package com.engine.kq.cmd.dutyrules;

import com.cloudstore.dev.api.util.Util_TableMap;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.general.PageIdConst;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import java.util.HashMap;
import java.util.Map;

/**
 * 值班规则--获取值班规则列表
 */
public class GetSearchListCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetSearchListCmd(Map<String, Object> params, User user) {
        this.user = user;
        this.params = params;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> resultMap = new HashMap<String, Object>();

        boolean canEdit = HrmUserVarify.checkUserRight("KQDutyRulesEdit:Edit", user);//是否具有编辑的权限;
        boolean canDelete = HrmUserVarify.checkUserRight("KQDutyRulesDelete:Delete", user);//是否具有删除的权限;
        boolean canLog = HrmUserVarify.checkUserRight("KQDutyRules:Log", user);//是否具有查看日志的权限;

        String backFields = " id,name,groupIds ";
        String sqlFrom = " from kq_DutyRules ";
        String sqlWhere = " where 1=1 and (isDelete is null or isDelete!=1) ";
        String orderBy = " id ";
        String pageUid = "1b3ad739-67fa-8b1e-1c19-6d37c1a33469-1";
        String operateString = "";
        operateString = "<operates width=\"20%\">";
        operateString += "<popedom transmethod=\"weaver.hrm.common.SplitPageTagOperate.getBasicOperate\" otherpara=\"" + canEdit + ":" + canDelete + ":" + canLog + "\"></popedom> ";
        operateString += "  <operate href=\"javascript:openDialog();\"  text=\"" + SystemEnv.getHtmlLabelName(93, user.getLanguage()) + "\" index=\"0\"/>";
        operateString += "  <operate href=\"javascript:doDel()\"    text=\"" + SystemEnv.getHtmlLabelName(91, user.getLanguage()) + "\"  index=\"1\"/>";
        operateString += "  <operate href=\"javascript:onLog()\"    text=\"" + SystemEnv.getHtmlLabelName(83, user.getLanguage()) + "\"  index=\"2\"/>";
        operateString += "</operates>";
        String tableString = "" +
                "<table pageId=\"Hrm:DutyRules\" pageUid=\"" + pageUid + "\" tabletype=\"checkbox\" pagesize=\"" + PageIdConst.getPageSize("Hrm:DutyRules", user.getUID(), PageIdConst.HRM) + "\" >" +
                "   <sql backfields=\"" + backFields + "\" sqlform=\"" + sqlFrom + "\" sqlwhere=\"" + Util.toHtmlForSplitPage(sqlWhere) + "\"  sqlorderby=\"" + orderBy + "\"  sqlprimarykey=\"id\" sqlsortway=\"asc\" sqlisdistinct=\"false\"/>"
                + operateString +
                "   <head>" +
                "       <col width=\"25%\" text=\"" + "值班规则名称" + "\" column=\"name\" transmethod=\"weaver.general.Util.formatMultiLang\" otherpara=\"" + user.getLanguage() + "\"  orderkey=\"name\"/>" +
                "       <col width=\"40%\" text=\"" + SystemEnv.getHtmlLabelName(388832, user.getLanguage()) + "\" column=\"id\" transmethod=\"com.engine.kq.util.KQTransMethod.getRuleContentDuty\" otherpara=\"" + user.getLanguage() + "\"/>" +
                "       <col width=\"25%\" text=\"" + SystemEnv.getHtmlLabelName(19374, user.getLanguage()) + "\" column=\"groupIds\" transmethod=\"com.engine.kq.util.KQTransMethod.getGroupName\" otherpara=\"" + user.getLanguage() + "\" />" +
                "   </head>" +
                "</table>";
        String sessionKey = pageUid + "_" + Util.getEncrypt(Util.getRandom());
        Util_TableMap.setVal(sessionKey, tableString);
        resultMap.put("sessionkey", sessionKey);
        return resultMap;
    }
}
